home *** CD-ROM | disk | FTP | other *** search
/ Family Fun / Family Fun.iso / joke1 / jokes_w / weird.pro < prev    next >
Internet Message Format  |  1992-01-07  |  14KB

  1. From dnalib@KCVAX.LDC.LU.SE Mon Oct  2 16:13:23 1989
  2. Date:    Fri, 29 Sep 89 11:00:00 EET
  3. Reply-To: Magnus Olsson <dnalib@KCVAX.LDC.LU.SE>
  4. Sender: Nutworks magazine & Other Nutty Stuff <NUTS@FINHUTC>
  5. From:    Magnus Olsson <dnalib@KCVAX.LDC.LU.SE>
  6. Subject:      Bored By Pascal?
  7. To:    Timo Kiravuo <kiravuo@KAMPI.HUT.FI>
  8.  
  9. Hi there!
  10.  
  11. Since this list seems to be silently dying, I'll try to revive it by
  12. actually *posting* something. The following files were circulating on the
  13. one of the Vaxen at the dept. of Computer Science here in Lund a few years
  14. ago. Nothing seems to be known about the author, except that he's never
  15. existed...
  16.  
  17. By the way, all three programs compile and run under VAX/VMS. For non-VAXers,
  18. the MTH$RANDOM function in the second program returns a random real between
  19. 0 and 1.
  20.  
  21.  
  22. Have fun!
  23.  
  24. Magnus
  25. (DNALIB@SELDC51)
  26.  
  27. ___________________________BORED-1.FOR_______________________________________
  28.  
  29. C       BORED BY PASCAL?
  30. C       ================
  31. C       PASCAL IS DESIGNED SO THAT YOU DON'T HAVE TO THINK
  32. C       WHILE PROGRAMMING. THIS IS GOOD FOR BEGINNERS BUT WILL
  33. C       BECOME A LITTLE BORING AFTER A WHILE.
  34. C       THIS LITTLE PROGRAM WAS WRITTEN TO DEMONSTRATE A
  35. C       NICE FEATURE OF FORTRAN: THE POSSIBILITY OF WRITING
  36. C       I N T E R E S T I N G  CODE.
  37. C       IF THIS PROGRAM WERE WRITTEN IN PASCAL, IT WOULD BE QUITE
  38. C       BANAL AND EASILY UNDERSTANDABLE EVEN TO THE AVERAGE TLTH
  39. C       MEMBER. THAT WOULD BE NO FUN, HOWEVER.
  40. C
  41. C       NOTE THE FOLLOWING NICETIES:
  42. C       * THE ABSENCE OF SENSIBLE COMMENTS-REAL PROGRAMMERS UNDERSTAND
  43. C         FORTRAN BETTER THAN ENGLISH!
  44. C       * THE ARITHMETIC IF-STATEMENTS (ADDING NICE FLAVOUR TO
  45. C         THE CODE)
  46. C       * THE WONDERFULLY CONCISE VARIABLE NAMES
  47. C       * THE H-FORMAT FOR ALPHANUMERIC OUTPUT ( A LIVING FOSSIL
  48. C         FROM THE HAPPY DAYS OF THE PUNCHED CARD)
  49. C       * THE NICE SPAGHETTI STRUCTURE - STRUCTURED PROGRAMMING
  50. C         IS ONLY FOR AMATEURS AND OLD LADIES
  51. C
  52. C       A SMALL REWARD IS OFFERED TO ANYBODY ABLE TO SAY WHAT
  53. C       THIS PROGRAM DOES (WITHOUT ACTUALLY RUNNING IT)
  54. C       SEND YOUR ANSWERS TO  TOM A.CRONA,
  55. C                             DEPARTMENT OF COMMUTER SCIENCE
  56. C                             AND NUMERICAL SYNTHESIS,
  57. C                             UNIVERSITY OF LUND
  58. C
  59. C       PLEASE NOTE THAT THIS PROGRAM IS NOT IN ANY WAY PATHOLOGICAL
  60. C       BUT A PERFECTLY NORMAL EXAMPLE OF WHAT PROGRAMMING WAS LIKE
  61. C       BACK IN THE GOLDEN DAYS WHEN COMPUTERS WERE COMPUTERS AND
  62. C       PROGRAMMERS WERE PROGRAMMERS...
  63.  
  64.  
  65.  10     WRITE (*,487)
  66.         READ (*,*) N
  67.         IF (N) 10,10,30
  68.  30     I1=2
  69.  97     I2=0
  70.  60     J=MOD(N,I1)
  71.         IF (J) 40,50,40
  72.  50     I2=I2+1
  73.         N=N/I1
  74.         GOTO 60
  75.  40     IF (I2-1) 70,80,90
  76.  70     I1=I1+2
  77.         IF (I1-4) 120,135,120
  78.  135    I1=3
  79.  120    IF (I1-N) 97,97,3
  80.  3      WRITE (*,65)
  81.         READ (*,*) I3
  82.         IF (I3) 3,130,10
  83.  130    STOP
  84.  80     WRITE (*,855) I1
  85.         GOTO 70
  86.  90     WRITE (*,930) I1,I2
  87.         GOTO 70
  88.  487    FORMAT (8H NUMBER?/)
  89.   65    FORMAT (20H CONTINUE? (1=Y,0=N)/)
  90.  855    FORMAT (I5)
  91.  930    FORMAT (I5,3H **,I5)
  92.  
  93. C       BE A CREATIVE PROGRAMMER - USE FORTRAN
  94. C       (C) SFRGOD (The Society For Revival of the Good Old
  95. C                   Days), Fortran section, 1984
  96.         END
  97.  
  98. ____________________________BORED-2.PAS_________________________________________
  99.  
  100. {   BORED BY PASCAL?    part 2
  101.     ==========================
  102.     In this degenerate age of the toy computer (by some weak souls
  103.     called "personal computer" or something like that) everyone learns
  104.     programming in kindergarten or at least in high school (if there's
  105.     any difference between those school forms). For this activity, a
  106.     language called BASIC is used almost exclusively. BASIC is rather
  107.     like a small subset of FORTRAN with many of its good features
  108.     amputated but with all of its drawbacks. Anyway, you can write
  109.     all kinds of programs in BASIC, and since it (fortunately!) lacks
  110.     any trace of structured constructs it promotes creative programming
  111.     the same way FORTRAN does and you get programmers who THINK while
  112.     they're programming.
  113.     When these persons start a higher education, they are forced
  114.     to write their programs in a "language" called Pascal and are
  115.     thereby quickly converted into well-adapted quiche eaters without
  116.     a trace of originality. This paper was written to point out a method
  117.     of solving this problem.
  118.  
  119.     Actually, you don't have to learn Pascal at all - it's much easier
  120.     to write your programs in BASIC and then translate them directly
  121.     into Pascal. As an example, consider the following program. It was
  122.     originally written in BASIC on a ZX80 (Yecch!) and then transformed
  123.     into syntactically perfect Pascal during the pause between two
  124.     lectures.
  125.     Most Pascal addicts turn away in disgust when seeing the words
  126.     GOTO and LABEL, but there's absolutely no reason to discriminate
  127.     these constructs - after all they're a part of the language (if that's
  128.     not too strong a word to use about Pascal). Why should any programmer
  129.     reject what is good enough for the compiler? Besides, the GOTO was
  130.     there first - structured programming is a much later (and unnecessary)
  131.     addition.
  132.  
  133.     By following this recipe, the young, undestroyed programmers can
  134.     continue writing their programs in BASIC, avoid learning more
  135.     Pascal than absolutely necessary and at the same time satisfy the
  136.     Pascal buffs of the university. }
  137.  
  138. PROGRAM NIM (INPUT,OUTPUT);
  139. {(c) Tom A. Crona 1984}
  140. LABEL 70,90,150,230,280,370,400,460,470,520,540,800,810,820;
  141. VAR J,S1,D,E,H,R,K : INTEGER; { WHO NEEDS FANCY LONG VARIABLE NAMES?}
  142.     A,B : ARRAY [0..3] OF INTEGER;
  143.     C   : ARRAY [0..3,0..3] OF INTEGER;
  144.  
  145. FUNCTION MTH$RANDOM(VAR SEED:INTEGER):REAL; EXTERNAL;
  146.  
  147.     BEGIN
  148.     WRITELN ('******* NIM *******');
  149.     WRITELN ('I HOPE YOU KNOW THE RULES OF NIM.');
  150.     WRITELN ('ANYWAY I''M NOT GOING TO RECITE THEM...');
  151.     WRITELN ('ENTER RANDOM SEED');
  152.     READ(S1);
  153.  70:FOR D:=0 TO 3 DO
  154.     A[D]:=TRUNC(MTH$RANDOM(S1)*15+1);
  155.  90:FOR D:=0 TO 3 DO
  156.     WRITELN (D+1,':',A[D]:2);
  157.     IF A[0]+A[1]+A[2]+A[3]>0 THEN GOTO 150;
  158.     WRITELN ('*I WON*');
  159.     GOTO 540;
  160. 150:WRITELN ('WHICH PILE?');
  161.     READ (D);
  162.     IF (D<1) OR (D>4) THEN GOTO 800;
  163.     WRITELN ('HOW MANY?');
  164.     READ (E);
  165.     IF (E<1) OR (E>A[D-1]) THEN GOTO 810;
  166.     A[D-1]:=A[D-1]-E;
  167.     D:=-1;
  168. 230:D:=D+1;
  169.     IF D=4 THEN GOTO 460;
  170.     FOR E:=0 TO 3 DO
  171.     B[E]:=A[E];
  172. 280:B[D]:=B[D]-1;
  173.     IF B[D]<0 THEN GOTO 230;
  174.     FOR E:=0 TO 3 DO
  175.     BEGIN
  176.     H:=B[E];
  177.     R:=16;
  178.     FOR J:=0 TO 3 DO
  179.     BEGIN
  180.     C[J,E]:=0;
  181.     R:=R DIV 2;
  182.     IF H<R THEN GOTO 370;
  183.     C[J,E]:=1;
  184.     H:=H-R;
  185. 370:END;
  186.     END;
  187.     E:=-1;
  188. 400:E:=E+1;
  189.     H:=C[E,0]+C[E,1]+C[E,2]+C[E,3];
  190.     IF H MOD 2>0 THEN GOTO 280;
  191.     IF E<3 THEN GOTO 400;
  192.     A[D]:=B[D];
  193.     GOTO 90;
  194. 460:D:=-1;
  195. 470:D:=D+1;
  196.     IF D=4 THEN GOTO 520;
  197.     IF A[D]=0 THEN GOTO 470;
  198.     A[D]:=A[D]-TRUNC(MTH$RANDOM(S1)*A[D]+1);
  199.     GOTO 90;
  200. 520:WRITELN ('YOU WON.');
  201. 540:WRITELN ('ENTER 1 IF YOU WISH TO CONTINUE, 0 OTHERWISE');
  202.     READ (K);
  203.     IF K=1 THEN GOTO 70;
  204.     GOTO 820;
  205. 800:WRITELN ('THERE IS NO SUCH PILE, STUPID!!!');
  206.     GOTO 150;
  207. 810:WRITELN ('TRYING TO CHEAT, EH?');
  208.     GOTO 150;
  209. 820:END.
  210.  
  211. ______________________________BORED-3.COB__________________________________
  212.  
  213. * BORED BY PASCAL? part 3
  214. * =======================
  215. * With the advent of Pascal, the art of writing interesting code is quickly
  216. * dying out among the younger programmers. I must confess that Pascal has
  217. * made it possible for (almost) everyone to write working programs,
  218. * but it also acts to stifle the true creativity expressed when writing
  219. * (and trying to debug) self-modifying, spaghetti-structured programs
  220. * written in any of the REAL programming languages. The only hope of
  221. * rescue for the "lost generation" of brand-new Pascal "programmers" is
  222. * to learn another language which is better suited for REAL programming.
  223. * In the previous articles of this series we have discussed
  224. * (i) the advantages of real, old-fashioned FORTRAN (not that miserable
  225. *     pseudo-Pascal known as FORTRAN 77)
  226. * (ii)the possibility of writing your programs in BASIC and then translating
  227. *     them directly into Pascal.
  228. * Some people may be repelled by the short and concise notation of these
  229. * languages - they are suffering from the illusion that a program has
  230. * to be self-explanatory so that every idiot can understand it.
  231. * (in fact it's advantageous to write incomprehensible program since in
  232. *  that case you (and not your competitors) will be called in to modify
  233. *  it when it's found out that the program won't function because the
  234. *  problem was incorrectly stated.)
  235. * There is a cure even for these unfortunate people, however. It's called
  236. * COBOL. The most distinct feature of this language is that it's extremely
  237. * verbose - in fact COBOL is more like a subset of English than a
  238. * programming language!
  239. * While this will (probably) take care of the need for documentation,
  240. * COBOL still has the properties that encourage creative programming,
  241. * like for example:
  242. *
  243. * + The total absence of any "structured" language elements
  244. * + The lack of local variables forcing you to remember all the
  245. *   variables you're using (good for your memory if it's a long program)
  246. * + The possibility of writing subroutines with multiple entry and
  247. *   exit points (not even BASIC has this last feature!)
  248. * + The ALTER statement for writing self-modifying code (see below)
  249. * + The good old GO TO statement enabling you to give the program
  250. *   any kind of structure you like.
  251. *
  252. * You should not be frightened by the fact that COBOL is said to be a
  253. * language for commercial programming. Below is a pure computational
  254. * program (it solves one of those nasty cubic equations)
  255. * written in COBOL which functions quite excellently. (Besides, I have
  256. * met programmers who actually write accounting programs in Algol...)
  257. *
  258. * Since the reader may not be acquainted with the semantics of COBOL,
  259. * I have departed from my holy principles and inserted some comments
  260. * into the code.
  261.  
  262. IDENTIFICATION DIVISION.
  263. PROGRAM-ID. SOLVE-CUBIC.
  264. AUTHOR. TOM A CRONA.
  265. INSTALLATION. LDC.
  266. DATE-WRITTEN. OCTOBER 22,1984.
  267. DATE-COMPILED. OCTOBER 22,1984.
  268. SECURITY. NONE.
  269.  
  270. ENVIRONMENT DIVISION.
  271. CONFIGURATION SECTION.
  272. SOURCE-COMPUTER. VAX.
  273. OBJECT-COMPUTER. VAX.
  274. SPECIAL-NAMES.
  275. DECIMAL-POINT IS COMMA.
  276.  
  277. DATA DIVISION.
  278. * If you think the variable declarations in Pascal are long and tedious,
  279. * have a look at this:
  280. WORKING-STORAGE SECTION.
  281. 77 ROOT-1       PICTURE S999V9(9) USAGE IS COMPUTATIONAL.
  282. 77 ROOT-2       PICTURE S999V9(9) USAGE IS COMPUTATIONAL.
  283. 77 EPS          PICTURE S999V9(9) USAGE IS COMPUTATIONAL.
  284. 77 X            PICTURE S999V9(9) USAGE IS COMPUTATIONAL.
  285. 77 OLD-X        PICTURE S999V9(9) USAGE IS COMPUTATIONAL.
  286. 77 LAST-X       PICTURE S999V9(9) USAGE IS COMPUTATIONAL.
  287. 77 NEW-X        PICTURE S999V9(9) USAGE IS COMPUTATIONAL.
  288. 77 Y            PICTURE S999V9(9) USAGE IS COMPUTATIONAL.
  289. 77 Y1           PICTURE S999V9(9) USAGE IS COMPUTATIONAL.
  290. 77 Y2           PICTURE S999V9(9) USAGE IS COMPUTATIONAL.
  291. 77 TEMP         PICTURE S999V9(9) USAGE IS COMPUTATIONAL.
  292. 77 TEMP2        PICTURE S999V9(9) USAGE IS COMPUTATIONAL.
  293. 77 EDITED-NBR   PICTURE ---9,9(9) USAGE IS DISPLAY.
  294. 77 ITERATIONS   PICTURE 99        USAGE IS COMPUTATIONAL.
  295. * I'm not going to tell you what all this means - consult the nearest
  296. * COBOL reference manual.
  297.  
  298. PROCEDURE DIVISION.
  299. COMPUTE-ROOTS. DISPLAY "THIS PROGRAM SOLVES 63x^3-9x^2-7x+1=0".
  300.         COMPUTE EPS = 10 ** -5.
  301.         PERFORM SOLVE THROUGH END-SOLVE MOVE LAST-X TO ROOT-1.
  302. * This is the COBOL equivalent of a subroutine call - and you specify both
  303. * entry and exit points yourself!
  304.         ALTER SKIP TO PROCEED TO ELIMINATE-1.
  305. * The above statement is a real goodie - it changes the GO TO END-FUNC below
  306. * to GO TO ELIMINATE-1.
  307.         PERFORM SOLVE THROUGH END-SOLVE MOVE LAST-X TO ROOT-2.
  308.         ALTER SKIP TO PROCEED TO ELIMINATE-2.
  309.         PERFORM SOLVE THROUGH END-SOLVE.
  310.         DISPLAY "NO MORE ROOTS".
  311.         STOP RUN.
  312.  
  313. SOLVE.  MOVE -1 TO OLD-X MOVE ALL ZEROES TO LAST-X, ITERATIONS.
  314. LOOP.   MOVE OLD-X TO X PERFORM COMPUTE-FUNCTION THROUGH END-FUNC
  315.         MOVE Y TO Y1.
  316.         MOVE LAST-X TO X PERFORM COMPUTE-FUNCTION THROUGH END-FUNC
  317.         MOVE Y TO Y2.
  318.         IF OLD-X - LAST-X IS LESS THAN EPS AND GREATER THAN - EPS
  319.                  GO TO END-SOLVE.
  320.         SUBTRACT OLD-X FROM LAST-X GIVING TEMP.
  321.         SUBTRACT Y1 FROM Y2 GIVING TEMP2.
  322.         MULTIPLY Y2 BY TEMP DIVIDE TEMP2 INTO TEMP.
  323.         SUBTRACT TEMP FROM LAST-X GIVING NEW-X.
  324.         MOVE LAST-X TO OLD-X MOVE NEW-X TO LAST-X.
  325.         ADD 1 TO ITERATIONS.
  326. * This way of writing aritmetical statements is peculiar to COBOL.
  327. * You are permitted to write COMPUTE NEW-X = LAST-X -
  328. * ( LAST-X - OLD-X ) / ( Y2 - Y1 )  instead, but that's no sport!
  329.         IF ITERATIONS IS GREATER THAN 20 DISPLAY "NO ROOT FOUND"
  330.                                                  STOP RUN.
  331.         IF Y2 IS LESS THAN - EPS OR GREATER THAN EPS GO TO LOOP.
  332. END-SOLVE. MOVE LAST-X TO EDITED-NBR DISPLAY "X=", EDITED-NBR.
  333. * Numbers are formatted for output by moving them to special "edited"
  334. * variabels like EDITED-NBR.These variables are defined by special
  335. * PICTURE clauses in the DATA DIVISION (if that makes you any wiser,
  336. * you don't need to read the rest)
  337.  
  338. COMPUTE-FUNCTION. MULTIPLY 7 BY X GIVING Y
  339.         SUBTRACT 1 FROM Y MULTIPLY X BY Y MULTIPLY 9 BY Y.
  340.         SUBTRACT 7 FROM Y MULTIPLY X BY Y ADD 1 TO Y.
  341. SKIP.   GO TO END-FUNC.
  342. * This statement is altered twice: first to GO TO ELIMINATE-1
  343. * and then to GO TO ELIMINATE-2. This self-modifying feature makes it
  344. * possible to write very elegant programs and is a real challenge to
  345. * any creative programmer.
  346. ELIMINATE-2. SUBTRACT ROOT-2 FROM X GIVING TEMP
  347.         DIVIDE TEMP INTO Y.
  348. ELIMINATE-1. SUBTRACT ROOT-1 FROM X GIVING TEMP
  349.         DIVIDE TEMP INTO Y.
  350. END-FUNC. EXIT.
  351.  
  352.  
  353.